<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.8.2.js"></script>

<script type="text/javascript">
    /*将post method 改变为delete*/
    function del(id) {
        alert(id);
        $.ajax({
            type:"delete",
            url:"/category/"+id,
            data:"{id:id}",
            dataType:"text",
            success:function (msg) {
                if(msg == "suc"){
                    alert("删除成功");
                    location.reload();
                }else{
                    alert("删除失败");
                }
            }
        })
    }
</script>

<div align="center">

</div>

<div style="width: 500px;margin:20px auto;text-align:center">
    <table align="center" border="1" cellspacing = "0">
        <tr>
            <td>id</td>
            <td>name</td>
            <td>编辑</td>
            <td>删除</td>
        </tr>
        <c:forEach items="${cs}" var="c" >
            <tr>
                <td>${c.id}</td>
                <td>${c.name}</td>
                <td><a href="${pageContext.request.contextPath}/category/${c.id}">编辑</a> </td>
                <td><button  onclick="del(${c.id})">删除</button></td>

            </tr>
        </c:forEach>

    </table>
    <form action="/category" method="post">
        <input type="hidden" name="_method" value="PUT">
        name:<input name = "name"><br>
        <button type="submit">提交</button>
    </form>

</div>